home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.alaska-software.com
/
2014.06.ftp.alaska-software.com.tar
/
ftp.alaska-software.com
/
3pp
/
mxsetup.old
/
{app}
/
MxTools.prg
< prev
next >
Wrap
Text File
|
2001-09-27
|
16KB
|
545 lines
//////////////////////////////////////////////////////////////////////
//
// MxTools.PRG
//
// Copyright:
// Maniacc Software Inc., (c) 2001. All rights reserved.
//
// Contents:
// General Tools and Black Box routines
//
//////////////////////////////////////////////////////////////////////
#include "Gra.ch"
#include "Xbp.ch"
#include "Mx.ch"
#include "Common.ch"
#include "Dll.ch"
#include "Appevent.ch"
*******************************************************************
*******************************************************************
** DATE FUNCTIONS NOT PROVIDED BY Xbase++ (replace XbtTools Functions)
*******************************************************************
*******************************************************************
*************************************
* Beginning of Month
*************************************
FUNCTION bom( dDate )
RETURN ctod(alltrim(str(month(dDate)))+'/1/'+alltrim(str(year(dDate))))
*************************************
* End of Month
*************************************
FUNCTION eom( dDate )
LOCAL nDay, i
LOCAL nMonth := month(dDate)
LOCAL nYear := year(dDate)
for i := 28 to 31
if !empty(ctod(alltrim(str(nMonth))+'/'+alltrim(str(i))+'/'+alltrim(str(year(dDate)))))
nDay := i
endif
next i
RETURN ctod(alltrim(str(nMonth))+'/'+alltrim(str(nDay))+'/'+alltrim(str(year(dDate))))
*************************************
* Add a Month
*************************************
FUNCTION addMonth( dDate, nMonths )
LOCAL nDay := day(dDate), i
LOCAL nMonth := month(dDate)
LOCAL nYear := year(dDate)
LOCAL cDate
nMonth := nMonth+nMonths
do while nMonth<1
nMonth := nMonth+12
nYear := nYear-1
enddo
do while nMonth>12
nMonth := nMonth-12
nYear := nYear+1
enddo
cDate := alltrim(str(nMonth))+"/"+alltrim(str(nDay))+"/"+alltrim(str(nYear))
do while empty(ctod(cDate))
nDay := nDay-1
cDate := alltrim(str(nMonth))+"/"+alltrim(str(nDay))+"/"+alltrim(str(nYear))
enddo
RETURN ctod(cDate)
*************************************
* MDY() Function
*************************************
FUNCTION mdy( dDate )
default dDate to date()
RETURN cMonth(dDate)+" "+str(Day(dDate),2)+ ", "+str(Year(dDate),4)
*************************************
* Is Leap Year
*************************************
FUNCTION IsLeapYear( dDate )
RETURN iif(!empty(stod(alltrim(str(year(dDate)))+"0229")),.T.,.F.)
*******************************************************************
*******************************************************************
* CLASS MxCalendar
*******************************************************************
*******************************************************************
CLASS MxCalendar FROM XbpStatic
EXPORTED:
VAR title
VAR GroupBox
VAR MonthBox, nMonth
VAR YearSpin, nYear
VAR oDay, nDay
VAR Calendar
VAR dMin, dMax
VAR aSize
VAR aDays
VAR dStartDate
METHOD init, create, getData, setData, setDays
ENDCLASS
*******************************************************************
* ( MxCalendar ) METHOD init
*******************************************************************
METHOD MxCalendar:init( oParent, oOwner, aPos, aSize, aPresParam, lVisible )
::dMin := ctod("01/01/1980")
::dMax := date()+(365*100)
::dStartDate := date()
::nMonth := month(date())
::nYear := year(date())
::nDay := day(date())
::title := " Date "
::aDays := array(6,7)
::asize := {210,205}
::XbpStatic:init( oParent, oOwner, aPos, aSize, aPresParam, lVisible )
::XbpStatic:clipChildren := .F.
::XbpStatic:clipSiblings := .F.
::XbpStatic:tabstop := .F.
::GroupBox := XbpStatic():new( self )
::GroupBox:type := XBPSTATIC_TYPE_GROUPBOX
::GroupBox:caption := ::title
::MonthBox := XbpComboBox():new( self )
::MonthBox:type := XBPCOMBO_DROPDOWNLIST
::MonthBox:clipSiblings := .T.
::MonthBox:tabstop := .T.
::MonthBox:Markmode := XBPLISTBOX_MM_SINGLE
::MonthBox:XbpListBox:itemSelected := { |uNil1, uNil2, oObj| ::nMonth := oObj:getdata()[1], ::setDays() }
::YearSpin := XbpSpinButton():new( self )
::YearSpin :setNumLimits( year(::dMin),year(::dMax) )
::YearSpin :clipSiblings := .T.
::YearSpin :tabstop := .T.
::YearSpin:keyboard := { | nKeyCode, uNIL2, oObj | iif(::nYear<>oObj:editbuffer(),(::nYear := oObj:getdata(), ::setDays()),Nil) }
::YearSpin:endSpin := { |uNil1, uNil2, oObj| ::nYear := oObj:getdata(), ::setDays() }
::Calendar := MxStatic():new( self )
::Calendar:type := XBPSTATIC_TYPE_RECESSEDBOX
::Calendar:options := XBPSTATIC_FRAMETHICK
::Calendar:tabStop := .T.
::Calendar:keyboard := { | nKeyCode, uNIL2, oObj | ;
iif(nKeyCode==xbeK_RIGHT.and.::nDay<day(eom(::getdata())),;
::nDay:=::nDay+1,;
iif(nKeyCode==xbeK_LEFT.and.::nDay>1,;
::nDay:=::nDay-1,;
iif(nKeyCode==xbeK_UP.and.::nDay>7,;
::nDay:=::nDay-7,;
iif(nKeyCode==xbeK_DOWN.and.::nDay<day(eom(::getdata()))-6,;
::nDay:=::nDay+7,;
Nil)))),;
::setDays() }
RETURN self
*******************************************************************
* ( MxCalendar ) METHOD create
*******************************************************************
METHOD MxCalendar:create( oParent, oOwner, aPos, aSize, aPresParam, lVisible )
LOCAL aMonths, oXbp
LOCAL i, j, aDayPos
::xbpStatic:create( oParent, oOwner, aPos, ::aSize, aPresParam, lVisible )
::GroupBox:caption := ::title
::GroupBox:create( ::XbpStatic,,{10,10},{190,188}, aPresParam, lVisible )
::MonthBox:create( ::XbpStatic,,{20,-10},{85,190}, aPresParam, lVisible )
aMonths := { "January","February","March","April",;
"May","June","July","August",;
"September","October","November","December" }
aEval(aMonths, {|c| ::MonthBox:addItem(c) } )
::MonthBox:datalink := { |x| IIf(x==NIL,::nMonth,::nMonth:=x)}
::MonthBox:setData()
::YearSpin:create( ::XbpStatic,,{115,160},{75,20}, aPresParam, lVisible )
::YearSpin:datalink := { |x| IIf(x==NIL,::nYear,::nYear:=x) }
::YearSpin:setdata()
::Calendar:create( ::XbpStatic,,{20,20},{170,133}, {{XBP_PP_BGCLR,GRA_CLR_WHITE}}, lVisible )
oXbp := XbpStatic():new()
oXbp:caption := " S M T W T F S "
oXbp:options := XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_VCENTER
oXbp:create( ::Calendar:drawingArea,,{-2,110},{170,18},{{XBP_PP_FGCLR,GRA_CLR_WHITE},;
{XBP_PP_BGCLR,GRA_CLR_DARKGRAY},;
{XBP_PP_COMPOUNDNAME,"10.Terminal"}} )
for i := 1 to 6
for j := 1 to 7
aDayPos := {((170/7)*(j-1))+3, 113-(i*18)}
::aDays[i,j] := XbpStatic():new()
::aDays[i,j]:options := XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_VCENTER
::aDays[i,j]:create( ::Calendar:drawingArea,,aDayPos,{18,14},;
{{XBP_PP_BGCLR,GRA_CLR_WHITE}} )
::aDays[i,j]:lbClick := { |aPos,uNil,oObj| ::oDay:setColorBG(GRA_CLR_WHITE),::oDay:setColorFG(GRA_CLR_BLACK),;
oOBj:setcolorBG(XBPSYSCLR_HILITEBACKGROUND),oOBj:setcolorFG(GRA_CLR_WHITE),;
::oDay := oObj,;
::nDay := val(::oDay:caption),;
setAppFocus(::Calendar) }
next j
next i
if ::dStartDate<>date()
::setData(::dStartDate)
else
::setDays()
endif
RETURN self
*******************************************************************
* ( MxCalendar ) METHOD setDays
*******************************************************************
METHOD MxCalendar:setDays()
LOCAL i, j, nNextDay, nDayStart, nLastDay
// ::Calendar:lockupdate(.T.)
nNextDay := 1
nDayStart := dow( stod( alltrim(str(::nYear))+padl(alltrim(str(::nMonth)),2,"0")+"01") )
nLastDay := day(eom( stod( alltrim(str(::nYear))+padl(alltrim(str(::nMonth)),2,"0")+"01") ))
for i := 1 to 6
for j := 1 to 7
do while i==1.and.j<nDayStart
::aDays[i,j]:setcaption("")
::aDays[i,j]:setcolorBG(GRA_CLR_WHITE)
::aDays[i,j]:setcolorFG(GRA_CLR_BLACK)
::aDays[i,j]:hide()
j++
enddo
if nNextDay<=nLastDay
::aDays[i,j]:setcaption(alltrim(str(nNextDay)))
::aDays[i,j]:show()
else
::aDays[i,j]:setcaption("")
::aDays[i,j]:hide()
endif
if nNextDay==::nDay
::aDays[i,j]:setcolorBG(XBPSYSCLR_HILITEBACKGROUND)
::aDays[i,j]:setcolorFG(GRA_CLR_WHITE)
::oDay := ::aDays[i,j]
else
::aDays[i,j]:setcolorBG(GRA_CLR_WHITE)
::aDays[i,j]:setcolorFG(GRA_CLR_BLACK)
endif
nNextDay++
next j
next i
// ::Calendar:lockupdate(.F.)
// ::Calendar:invalidateRect()
RETURN self
*******************************************************************
* ( MxCalendar ) METHOD getData
*******************************************************************
METHOD MxCalendar:getdata()
RETURN stod( alltrim(str(::nYear))+;
padl(alltrim(str(::nMonth)),2,"0")+;
padl(alltrim(::oDay:caption),2,"0") )
*******************************************************************
* ( MxCalendar ) METHOD setData
*******************************************************************
METHOD MxCalendar:setdata(dDate)
::nMonth := month(::dStartDate)
::MonthBox:setData()
::nYear := year(::dStartDate)
::YearSpin:setData()
::nDay := day(::dStartDate)
::setDays()
RETURN .T.
*******************************************************************
*******************************************************************
* FUNCTION MxGetDate - Returns the Date Selected - uses a MxCalendar
* or an empty date if Cancel or "ESC" is selected
*******************************************************************
*******************************************************************
FUNCTION MxGetDate( oDa, aPos, cTitle, dStartDate )
LOCAL oDlg, oFocus, oCalendar, oXbp, mp1, mp2, nEvent
LOCAL lgetDate := .F., lDone := .F., dDate := stod("20001240")
DEFAULT dStartDate to date()
cTitle := iif(empty(cTitle)," Date ",cTitle)
oDlg := oDa
do while oDlg:setParent()<>AppDeskTop()
aPos[1] := aPos[1]+oDlg:setParent():currentPos()[1]
aPos[2] := aPos[2]+oDlg:setParent():currentPos()[2]
oDlg := oDlg:setParent()
enddo
oDlg := XbpDialog():new()
oDlg:sysMenu := .F.
oDlg:clipSiblings := .T.
oDlg:border := XBPDLG_RAISEDBORDERTHICK_FIXED
oDlg:paint := { |aRect,uNil2,self|self:childList()[1]:invalidateRect() }
oDlg:create( AppDeskTop(),oDa,aPos,{216,255},,.F. )
oCalendar := MxCalendar():new()
oCalendar:title := cTitle
oCalendar:dStartDate := dStartDate
oCalendar:create( oDlg:drawingArea,,{0,30},{0,0} )
oXbp := XbpPushButton():new()
oXbp:caption := "OK"
oXbp:tabStop := .T.
oXbp:create( oDlg:drawingArea,,{23,10},{80,20})
oXbp:activate := { || lDone := .T., lgetDate := .T.}
oXbp := XbpPushButton():new()
oXbp:caption := "Cancel"
oXbp:tabStop := .T.
oXbp:create( oDlg:drawingArea,,{103,10},{80,20})
oXbp:activate := { || lDone := .T.}
MxDisableSiblings( oDlg )
oDlg:show()
oDlg:setModalState(XBP_DISP_APPMODAL)
oFocus := setAppFocus(oDlg)
setAppFocus(oDlg:drawingArea:childList()[len(oDlg:drawingArea:childList())-1])
do while !lDone
nEvent := AppEvent( @mp1,@mp2,@oXbp )
oXbp:handleEvent( nEvent, mp1, mp2 )
if nEvent == xbeP_Keyboard.and.mp1==xbeK_ESC
lDone := .T.
elseif nEvent == xbeP_Keyboard.and.mp1>256
sleep(2)
endif
enddo
if lGetDate
dDate := oCalendar:getdata()
endif
oDlg:setModalState(XBP_DISP_MODELESS)
MxEnableSiblings( oDlg )
oDlg:destroy()
nEvent := xbeP_None
SetAppFocus(oFocus)
RETURN dDate
*******************************************************************
*******************************************************************
* FUNCTION MxShowMsg - displays a message for nSeconds
*******************************************************************
*******************************************************************
FUNCTION MxShowMsg(cMessage, nSeconds)
LOCAL oXbp, oCaption
oXbp := MxStatic():new()
oXbp:type := MXSTATIC_TYPE_RAISEDFRAME
oXbp:nBorderWidth := 8
oXbp:nColorFrame := GRA_CLR_RED
oXbp:nColorBG := GRA_CLR_WHITE
oXbp:create( appDeskTop(),setAppWindow():drawingArea,{(appDeskTop():currentSize()[1]-200)/2,(appDeskTop():currentSize()[2]-100)/2},{200,100})
oCaption := MxStatic():new()
oCaption:caption := cMessage
oCaption:options := XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_VCENTER
oCaption:create(oXbp:drawingArea,,{5,5},{oXbp:drawingArea:currentSize()[1]-10,oXbp:drawingArea:currentSize()[2]-10},{{XBP_PP_COMPOUNDNAME,"9.Arial Bold"}})
sleep( nSeconds*100 )
oXbp:destroy()
RETURN .T.
*******************************************************************
*******************************************************************
* FUNCTION MxPlayWav()
*******************************************************************
*******************************************************************
FUNCTION MxPlayWav(cWavfile)
LOCAL nDll := DllLoad("WINMM.DLL")
if file(cWavfile).and.nDll<>0
DllCall(nDll,DLL_STDCALL,"PlaySoundA",cWavfile,0,0x00020000+0x0001)
DllUnload( nDll )
endif
RETURN .T.
*******************************************************************
*******************************************************************
* FUNCTION MxCalc() converts xPixels down from Top to xPixels up
*******************************************************************
*******************************************************************
FUNCTION MxCalc( oDa, aPos )
RETURN { aPos[1],oDa:currentSize()[2]-aPos[2] }
************************************************
* FUNCTION DtoR() - Convert Degrees to Radians
************************************************
FUNCTION DtoR(nAngle)
LOCAL nPi := 3.14159265358979
do while nAngle>=360
nAngle := nAngle-360
enddo
RETURN nPi*nAngle/180
************************************************
* FUNCTION Cos() - calculate Cosine from Radians
************************************************
FUNCTION cos(nRadians)
LOCAL n := nRadians, nCos
LOCAL nPi := 3.14159265358979
LOCAL lReverse := .F.
if n>nPi
n := (2*nPi)-n
endif
if n>nPi/2
n := nPi-n
endif
if n>nPi/4
n := nPi/2-n
lReverse := .T.
endif
n := n*n
nCos := abs(1-(n/2)+(n**2/24)-(n**3/720)+(n**4/40330)-(n**5/3628800))
if lReverse
nCos := abs(sqrt(1-(nCos**2)))
endif
if nRadians>nPi/2.and.nRadians<3*nPi/2
nCos := -nCos
endif
RETURN nCos
************************************************
* FUNCTION Sin() - calculate sine from Radians
************************************************
FUNCTION sin(nRadians)
LOCAL nPi := 3.14159265358979
LOCAL nCos := cos(nRadians)
LOCAL nSin := abs(sqrt(1-(nCos**2)))
if nRadians>nPi
nSin := -nSin
endif
RETURN nSin
************************************************
* FUNCTION SinCos() - calculate sine from Radians
************************************************
FUNCTION sinCos(nRadians)
LOCAL nPi := 3.14159265358979
LOCAL nCos := cos(nRadians)
LOCAL nSin := abs(sqrt(1-(nCos**2)))
if nRadians>nPi
nSin := -nSin
endif
RETURN {nSin,nCos}